package RPGame;

import static org.newdawn.slick.Input.*;

public class EntityPlayer extends EntityActor {

	private boolean rightKeyDown;
	private boolean leftKeyDown;
	private boolean upKeyDown;
	private boolean downKeyDown;

	public EntityPlayer(Game game) {
		super(game, "RPGame/sprites/base_char.png", 32, 32);
	}
	
	@Override
	public void update(int delta) {
		if(!rightKeyDown && !leftKeyDown && !upKeyDown && !downKeyDown) {
			action = ActorState.IDLING;
			vX = 0f;
			vY = 0f;
		} else {
			action = ActorState.WALKING;
		}
		super.update(delta);
	}
	
	public void keyPressed(int key, char c) {
		switch(key) {
			case KEY_RIGHT:
				rightKeyDown = true;
				vX = 0.1f;
				direction = Direction.RIGHT;
				break;
			case KEY_LEFT:
				leftKeyDown = true;
				vX = -0.1f;
				direction = Direction.LEFT;
				break;
			case KEY_UP:
				upKeyDown = true;
				vY = -0.1f;
				direction = Direction.UP;
				break;
			case KEY_DOWN:
				downKeyDown = true;
				vY = 0.1f;
				direction = Direction.DOWN;
				break;
		}
	}
	
	public void keyReleased(int key, char c) {
		switch(key) {
			case KEY_RIGHT:
				rightKeyDown = false;
				break;
			case KEY_LEFT:
				leftKeyDown = false;
				break;
			case KEY_UP:
				upKeyDown = false;
				break;
			case KEY_DOWN:
				downKeyDown = false;
				break;
		}
	}
}
